<template>
  <view class="user">
    <view class="heard">
      <view class="item1">
        <u-avatar
            :src="IMG_URL+userInfo.avatar"
            size="110" class="avatar"></u-avatar>
      </view>
      <view class="item2">
        <view class="name">
          <view>
            {{userInfo.nickname}}
          </view>
          <view class="identity">
            <u-tag v-if="userInfo.flag==0" shape="circle" text="普通用户" type="success" />
            <u-tag v-else-if="userInfo.flag==3" shape="circle" text="互娱师" type="success" />
            <u-tag v-else-if="userInfo.flag==2" shape="circle" text="商家" type="success" />
          </view>
		  <view v-if="gamerInfo.f_business_id!=0" class="identity" @click="updateBinding()">
			  <u-tag v-if="is_binding==0" shape="circle" text="下班" type="success" />
			  <u-tag v-else-if="is_binding==1" shape="circle" text="上班" type="success" />
		  </view>
        </view>
        <view class="sign">{{userInfo.signature}}</view>
      </view>
      <view class="item3" @click="toEditData()">
        <view>
          <u-icon size="24" name="/static/image/userDetails/jiantou1.png"></u-icon>
        </view>
      </view>
    </view>
    <view class="menu1">
      <view class="item" @click="toUserPre()">
        <view class="txt1">{{ couponNum }}</view>
        <view class="txt2">优惠券</view>
      </view>
      <view class="line"></view>
      <view class="item" @click="toCollect">
        <view class="txt1">{{statusb}}</view>
        <view class="txt2">收藏</view>
      </view>
      <view class="line"></view>
      <view class="item" @click="toUserBalance()">
        <view class="txt1">{{userInfo.account_money}}</view>
        <view class="txt2">姊曰币</view>
      </view>
    </view>
    <view class="menu2">
      <view class="title">
        <view>常用功能</view>
      </view>
      <view class="tag">
        <view v-if="userInfo.flag == 1" class="item" style="margin-right: 70rpx;margin-left: 20rpx" @click="toBusData()">
          <u-icon size="50" name="/static/image/userDetails/shangjia.png"></u-icon>
          <view>商家入驻</view>
        </view>
        <view v-if="userInfo.flag == 1"  class="item" style="margin-right: 70rpx" @click="toUserPage()">
          <u-icon size="50" name="/static/image/userDetails/geren.png"></u-icon>
          <view>个人入驻</view>
        </view>
        <view class="item" style="margin-right: 70rpx" @click="fw">
          <u-icon size="50" name="/static/image/userDetails/kefu.png"></u-icon>
          <view>客服咨询</view>
        </view>
        <view class="item" @click="toAbout()">
          <u-icon size="50" name="/static/image/userDetails/about.png"></u-icon>
          <view>关于我们</view>
        </view>
      </view>
    </view>
<!--  v-if="userInfo.flag == 2"  -->
    <view v-if="userInfo.flag == 2"  class="menu2" style="margin-top: 20rpx">
      <view class="title">
        <view>商户操作</view>
      </view>
      <view class="tag" >
        <view class="item" style="margin-right: 70rpx;" @click="toBusData()">
          <u-icon size="50" name="/static/image/userDetails/shangjia.png"></u-icon>
          <view>信息修改</view>
        </view>
        <view class="item" style="margin-right: 70rpx" @click="toShopGoods()">
          <u-icon size="50" name="/static/image/userDetails/shangping.png"></u-icon>
          <view>我的商品</view>
        </view>
<!--        <view class="item" style="margin-right: 70rpx" @click="toShopImg()">-->
<!--          <u-icon size="50" name="/static/image/userDetails/xiangce.png"></u-icon>-->
<!--          <view>封面上传</view>-->
<!--        </view>-->
      </view>
    </view>
    <view v-if="userInfo.flag == 3" class="menu2" style="margin-top: 20rpx">
      <view class="title">
        <view>互娱师操作</view>
      </view>
      <view class="tag">
        <view class="item" style="margin-right: 70rpx" @click="toUserPage()">
          <u-icon size="50" name="/static/image/userDetails/ziliao.png"></u-icon>
          <view>资料修改</view>
        </view>
        <view class="item" style="margin-right: 70rpx" @click="toGamerImg()">
          <u-icon size="50" name="/static/image/userDetails/xiangce.png"></u-icon>
          <view>我的照片</view>
        </view>
<!--        <view class="item" style="margin-right: 70rpx" @click="">-->
<!--          <u-icon size="50" name="/static/image/userDetails/bangding.png"></u-icon>-->
<!--          <view>绑定商家</view>-->
<!--        </view>-->

		<!-- 余额提现 -->
        <!-- <view class="item" style="margin-right: 60rpx" @click="Withdrawals">
          <u-icon size="50" name="/static/image/userDetails/tixian.png"></u-icon>
          <view>余额提现</view>
        </view> -->
      </view>
    </view>

    <u-popup v-model="show" mode="bottom" class="popModel">
      <view class="add">请添加客服微信</view>
      <!-- <image class="viewImg" src="https://img0.baidu.com/it/u=2600511206,4088903848&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"></image> -->
      <image class="viewImg" mode="aspectFit" :src="customerInfo"/>
      <view class="saomiao">长按图片扫描</view>
    </u-popup>
  </view>
</template>

<script>
import {getFw} from "../../api/customServer";
import {getUserSaveBusiness, getUserSaveGamer} from "../../api/user";
import {IMG_URL} from "../../config/URL";
import {updateBinding} from "../../api/gamer.js";

export default {
  onShow() {
    this.userInfo =  uni.getStorageSync('userInfo');
	  this.gamerInfo = uni.getStorageSync('gamerInfo')
	  this.is_binding = this.gamerInfo.is_binding
    this.couponNum = uni.getStorageSync('couponNum');
    this.getUserSaveNum(this.userInfo.id)
  },
  name: "index",
  data() {
    return {
      IMG_URL,
      showFalse:false,
      userInfo:{},
	  gamerInfo:{},
	  is_binding:0,
      couponNum:'',
      tagStatic:true,
      money:"1000",
      statusb:0,
      show:false,
      customerInfo:'',
      userSaveGamer:[],
      userSaveBusiness:[],
    }
  },
  methods: {
	  async updateBinding(){
		  const a = await updateBinding({
			  userId:this.userInfo.id,
			  })
		  if(a.data.code != 200){
			  return
		  }
		  if(this.is_binding==0){
			  this.is_binding=1
			  this.gamerInfo.is_binding=1
			  uni.setStorageSync('gamerInfo',this.gamerInfo)
		  }else if(this.is_binding==1){
			  this.is_binding=0
			  this.gamerInfo.is_binding=0
			  uni.setStorageSync('gamerInfo',this.gamerInfo)
		  }

		  uni.showToast({
		    title: '修改成功',
		    duration: 2000,
		    icon:'none',
		  });

	  },
	  //提现
	  Withdrawals(){
		  console.log(uni.getStorageSync("userInfo"));
		  uni.navigateTo({
		  	url:"/subPages/subUser/Withdrawals/index"
		  })
	  },
    async getUserSaveNum(id){
      const userSaveGamer = await getUserSaveGamer(id)
      const userSaveBusiness = await getUserSaveBusiness(id)
      let s = userSaveGamer.data.data
      let d = userSaveBusiness.data.data
      let s1,d1
      if(s==null){
        s1 = 0
      }else{
        s1 = s.length
      }
      if(d==null){
        d1 = 0
      }else{
        d1 = d.length
      }
      this.statusb = s1+d1
      this.userSaveGamer = s
      this.userSaveBusiness = d
    },
	
	// 客服
    async fw(){
      this.show = !this.show;
      let link = await getFw();
	  this.customerInfo = IMG_URL + link.data.data[0].img
    },

    //跳转相关
    toEditData() {
      if (uni.getStorageSync('userInfo')) {
        uni.navigateTo({url: "/subPages/subUser/UserPage/index"})
      } else {
        uni.navigateTo({url: '/subPages/subRegister/index'})
      }
      // uni.navigateTo({url: '/subPages/subRegister/index'})
    },

    toUserPre() {
      uni.navigateTo({
        url:'/subPages/subUser/Preferential/index'
      })
    },

    toCollect() {
      let data = {
        userSaveGamer: this.userSaveGamer,
        userSaveBusiness: this.userSaveBusiness,
      }
      uni.navigateTo({ url: "/subPages/subCollect/index?data=" + encodeURIComponent(JSON.stringify(data))})
    },

    toUserBalance(){
      uni.navigateTo({
        url:'/subPages/subUser/userBalance/index'
      })
    },

    toBusData(){
      uni.navigateTo({ url: '/subPages/subUser/businessettled/businessettled' })
    },

    async toUserPage(){
      uni.navigateTo({ url: '/subPages/subUser/UserSettled/index' })
      uni.hideLoading();
    },

    toAbout() {
      uni.navigateTo({ url: '/subPages/subAbout/index' })
    },

    toShopGoods() {
      uni.navigateTo({ url: '/subPages/subShops/shopGoods/index' })
    },
    toGamerImg(){
      uni.navigateTo({ url: '/subPages/subUser/UserSettled/gamerImg/index' })
    },
    toShopImg() {
      uni.navigateTo({ url: '/subPages/subUser/businessettled/shopImg/index' })
    }

  }
}
</script>


<style lang="scss" scoped>
.user {
  min-height: 100vh;
  padding: 30rpx;
  display: flex;
  flex-direction: column;
  background-color: #f6f6f9;

  .heard {
    display: flex;

    .item1 {
      flex: 1;
    }

    .item2 {
      flex: 4;
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-left: 20rpx;

      .name {
        font-size: 40rpx;
        color: #505050;
        margin-bottom: 10rpx;
        display: flex;
        .identity{
          margin-left: 20rpx;
          display: flex;
        }
      }

      .sign {
        font-size: 20rpx;
        color: #aeaeae;
      }
    }

    .item3 {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      color: #aeaeae;
    }
  }

  .menu1 {
    margin: 40rpx 0rpx;
    display: flex;
    justify-content: space-between;

    .item {
      display: flex;
      flex-direction: column;
      flex: 1;
      justify-content: center;
      align-items: center;

      .txt1 {
        color: black;
        font-size: 40rpx;
      }

      .txt2 {
        color: #aeaeae;
        font-size: 22rpx;
      }
    }

    .line {
      width: 2rpx;
      background-color: #efeff2;
    }
  }

  .menu2 {
    display: flex;
    flex-direction: column;
    background-color: #fdfdfd;
    padding: 20rpx 30rpx;
    border-radius: 10rpx;

    .title {
      display: flex;
      justify-content: space-between;
      color: black;
      font-weight: bolder;
      font-size: 30rpx;
      margin-bottom: 35rpx;
    }

    .tag {
      display: flex;
      .item {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        view {
          margin-top: 15rpx;
          color: black;
          font-size: 24rpx;
        }
      }
    }

  }

  .popModel{
    width: 100%;
    .add{
      font-size: 50rpx;
      text-align: center;
      margin-top: 30rpx;
    }
    .viewImg{
      // 上右下左
      margin: 10rpx 50rpx 0 50rpx;
    }
    .imageView{
      margin-top: 18rpx;
      width: 150rpx;
      height: 140rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .saomiao{
      font-size: 30rpx;
      text-align: center;
      margin-bottom: 80rpx;
    }
  }
}
</style>
